home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / samples / docbook / xsl / html / qandaset.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-09  |  10.8 KB  |  315 lines  |  [□□□□/□□□□]

  1. qandaset.xsl(‘π¢tÚπ¢tÚÅÅ∫˛<?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  4.                 exclude-result-prefixes="doc"
  5.                 version='1.0'>
  6.  
  7. <!-- ********************************************************************
  8.      $Id: qandaset.xsl,v 1.1 2002/05/29 09:55:49 dan Exp $
  9.      ********************************************************************
  10.  
  11.      This file is part of the XSL DocBook Stylesheet distribution.
  12.      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  13.      and other information.
  14.  
  15.      ******************************************************************** -->
  16.  
  17. <!-- ==================================================================== -->
  18.  
  19. <xsl:template match="qandaset">
  20.   <xsl:variable name="title" select="title"/>
  21.   <xsl:variable name="preamble" select="*[name(.) != 'title'
  22.                                           and name(.) != 'titleabbrev'
  23.                                           and name(.) != 'qandadiv'
  24.                                           and name(.) != 'qandaentry']"/>
  25.   <xsl:variable name="label-width">
  26.     <xsl:call-template name="dbhtml-attribute">
  27.       <xsl:with-param name="pis"
  28.                       select="processing-instruction('dbhtml')"/>
  29.       <xsl:with-param name="attribute" select="'label-width'"/>
  30.     </xsl:call-template>
  31.   </xsl:variable>
  32.  
  33.   <xsl:variable name="table-summary">
  34.     <xsl:call-template name="dbhtml-attribute">
  35.       <xsl:with-param name="pis"
  36.                       select="processing-instruction('dbhtml')"/>
  37.       <xsl:with-param name="attribute" select="'table-summary'"/>
  38.     </xsl:call-template>
  39.   </xsl:variable>
  40.  
  41.   <xsl:variable name="cellpadding">
  42.     <xsl:call-template name="dbhtml-attribute">
  43.       <xsl:with-param name="pis"
  44.                       select="processing-instruction('dbhtml')"/>
  45.       <xsl:with-param name="attribute" select="'cellpadding'"/>
  46.     </xsl:call-template>
  47.   </xsl:variable>
  48.  
  49.   <xsl:variable name="cellspacing">
  50.     <xsl:call-template name="dbhtml-attribute">
  51.       <xsl:with-param name="pis"
  52.                       select="processing-instruction('dbhtml')"/>
  53.       <xsl:with-param name="attribute" select="'cellspacing'"/>
  54.     </xsl:call-template>
  55.   </xsl:variable>
  56.  
  57.   <xsl:variable name="toc">
  58.     <xsl:call-template name="dbhtml-attribute">
  59.       <xsl:with-param name="pis"
  60.                       select="processing-instruction('dbhtml')"/>
  61.       <xsl:with-param name="attribute" select="'toc'"/>
  62.     </xsl:call-template>
  63.   </xsl:variable>
  64.  
  65.   <xsl:variable name="toc.params">
  66.     <xsl:call-template name="find.path.params">
  67.       <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  68.     </xsl:call-template>
  69.   </xsl:variable>
  70.  
  71.   <div class="{name(.)}">
  72.     <xsl:apply-templates select="$title"/>
  73.     <xsl:if test="contains($toc.params, 'toc') and $toc != '0'">
  74.       <xsl:call-template name="process.qanda.toc"/>
  75.     </xsl:if>
  76.     <xsl:apply-templates select="$preamble"/>
  77.     <table border="0">
  78.       <xsl:if test="$table-summary != ''">
  79.         <xsl:attribute name="summary">
  80.           <xsl:value-of select="$table-summary"/>
  81.         </xsl:attribute>
  82.       </xsl:if>
  83.  
  84.       <xsl:if test="$cellpadding != ''">
  85.         <xsl:attribute name="cellpadding">
  86.           <xsl:value-of select="$cellpadding"/>
  87.         </xsl:attribute>
  88.       </xsl:if>
  89.  
  90.       <xsl:if test="$cellspacing != ''">
  91.         <xsl:attribute name="cellspacing">
  92.           <xsl:value-of select="$cellspacing"/>
  93.         </xsl:attribute>
  94.       </xsl:if>
  95.  
  96.       <col align="left">
  97.         <xsl:attribute name="width">
  98.           <xsl:choose>
  99.             <xsl:when test="$label-width != ''">
  100.               <xsl:value-of select="$label-width"/>
  101.             </xsl:when>
  102.             <xsl:otherwise>1%</xsl:otherwise>
  103.           </xsl:choose>
  104.         </xsl:attribute>
  105.       </col>
  106.       <tbody>
  107.         <xsl:apply-templates select="qandaentry|qandadiv"/>
  108.       </tbody>
  109.     </table>
  110.   </div>
  111. </xsl:template>
  112.  
  113. <xsl:template match="qandaset/title">
  114.   <xsl:variable name="qalevel">
  115.     <xsl:call-template name="qanda.section.level"/>
  116.   </xsl:variable>
  117.   <xsl:element name="h{string(number($qalevel)+1)}">
  118.     <xsl:attribute name="class">
  119.       <xsl:value-of select="name(.)"/>
  120.     </xsl:attribute>
  121.     <xsl:apply-templates/>
  122.   </xsl:element>
  123. </xsl:template>
  124.  
  125. <xsl:template match="qandadiv">
  126.   <xsl:variable name="preamble" select="*[name(.) != 'title'
  127.                                           and name(.) != 'titleabbrev'
  128.                                           and name(.) != 'qandadiv'
  129.                                           and name(.) != 'qandaentry']"/>
  130.  
  131.   <xsl:if test="title">
  132.     <tr class="qandadiv">
  133.       <td align="left" valign="top" colspan="2">
  134.         <xsl:call-template name="anchor">
  135.           <xsl:with-param name="conditional" select="0"/>
  136.         </xsl:call-template>
  137.         <xsl:apply-templates select="title"/>
  138.       </td>
  139.     </tr>
  140.   </xsl:if>
  141.  
  142.   <xsl:variable name="toc.params">
  143.     <xsl:call-template name="find.path.params">
  144.       <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  145.     </xsl:call-template>
  146.   </xsl:variable>
  147.   <xsl:if test="contains($toc.params, 'toc')">
  148.     <tr class="toc" colspan="2">
  149.       <td align="left" valign="top" colspan="2">
  150.         <xsl:call-template name="process.qanda.toc"/>
  151.       </td>
  152.     </tr>
  153.   </xsl:if>
  154.   <xsl:if test="$preamble">
  155.     <tr class="toc" colspan="2">
  156.       <td align="left" valign="top" colspan="2">
  157.         <xsl:apply-templates select="$preamble"/>
  158.       </td>
  159.     </tr>
  160.   </xsl:if>
  161.   <xsl:apply-templates select="qandadiv|qandaentry"/>
  162. </xsl:template>
  163.  
  164. <xsl:template match="qandadiv/title">
  165.   <xsl:variable name="qalevel">
  166.     <xsl:call-template name="qandadiv.section.level"/>
  167.   </xsl:variable>
  168.  
  169.   <xsl:element name="h{string(number($qalevel)+1)}">
  170.     <xsl:attribute name="class">
  171.       <xsl:value-of select="name(.)"/>
  172.     </xsl:attribute>
  173.     <xsl:call-template name="anchor">
  174.       <xsl:with-param name="node" select=".."/>
  175.       <xsl:with-param name="conditional" select="0"/>
  176.     </xsl:call-template>
  177.     <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
  178.     <xsl:value-of select="$autotoc.label.separator"/>
  179.     <xsl:text> </xsl:text>
  180.     <xsl:apply-templates/>
  181.   </xsl:element>
  182. </xsl:template>
  183.  
  184. <xsl:template match="qandaentry">
  185.   <xsl:apply-templates/>
  186. </xsl:template>
  187.  
  188. <xsl:template match="question">
  189.   <xsl:variable name="deflabel">
  190.     <xsl:choose>
  191.       <xsl:when test="ancestor-or-self::*[@defaultlabel]">
  192.         <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
  193.                               /@defaultlabel"/>
  194.       </xsl:when>
  195.       <xsl:otherwise>
  196.         <xsl:value-of select="qanda.defaultlabel"/>
  197.       </xsl:otherwise>
  198.     </xsl:choose>
  199.   </xsl:variable>
  200.  
  201.   <tr class="{name(.)}">
  202.     <td align="left" valign="top">
  203.       <xsl:call-template name="anchor">
  204.         <xsl:with-param name="node" select=".."/>
  205.         <xsl:with-param name="conditional" select="0"/>
  206.       </xsl:call-template>
  207.       <xsl:call-template name="anchor">
  208.         <xsl:with-param name="conditional" select="0"/>
  209.       </xsl:call-template>
  210.  
  211.       <b>
  212.         <xsl:apply-templates select="." mode="label.markup"/>
  213.       </b>
  214.     </td>
  215.     <td align="left" valign="top">
  216.       <xsl:choose>
  217.         <xsl:when test="$deflabel = 'none' and not(label)">
  218.           <b><xsl:apply-templates select="*[name(.) != 'label']"/></b>
  219.         </xsl:when>
  220.         <xsl:otherwise>
  221.           <xsl:apply-templates select="*[name(.) != 'label']"/>
  222.         </xsl:otherwise>
  223.       </xsl:choose>
  224.     </td>
  225.   </tr>
  226. </xsl:template>
  227.  
  228. <xsl:template match="answer">
  229.   <tr class="{name(.)}">
  230.     <td align="left" valign="top">
  231.       <xsl:call-template name="anchor"/>
  232.       <b>
  233.         <xsl:apply-templates select="." mode="label.markup"/>
  234.       </b>
  235.     </td>
  236.     <td align="left" valign="top">
  237.       <xsl:apply-templates select="*[name(.) != 'label']"/>
  238.     </td>
  239.   </tr>
  240. </xsl:template>
  241.  
  242. <xsl:template match="label">
  243.   <xsl:apply-templates/>
  244. </xsl:template>
  245.  
  246. <!-- ==================================================================== -->
  247.  
  248. <xsl:template name="process.qanda.toc">
  249.   <dl>
  250.     <xsl:apply-templates select="qandadiv" mode="qandatoc.mode"/>
  251.     <xsl:apply-templates select="qandaentry" mode="qandatoc.mode"/>
  252.   </dl>
  253. </xsl:template>
  254.  
  255. <xsl:template match="qandadiv" mode="qandatoc.mode">
  256.   <dt><xsl:apply-templates select="title" mode="qandatoc.mode"/></dt>
  257.   <dd><xsl:call-template name="process.qanda.toc"/></dd>
  258. </xsl:template>
  259.  
  260. <xsl:template match="qandadiv/title" mode="qandatoc.mode">
  261.   <xsl:variable name="qalevel">
  262.     <xsl:call-template name="qandadiv.section.level"/>
  263.   </xsl:variable>
  264.   <xsl:variable name="id">
  265.     <xsl:call-template name="object.id">
  266.       <xsl:with-param name="object" select="parent::*"/>
  267.     </xsl:call-template>
  268.   </xsl:variable>
  269.  
  270.   <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
  271.   <xsl:value-of select="$autotoc.label.separator"/>
  272.   <xsl:text> </xsl:text>
  273.   <a>
  274.     <xsl:attribute name="href">
  275.       <xsl:call-template name="href.target">
  276.         <xsl:with-param name="object" select="parent::*"/>
  277.       </xsl:call-template>
  278.     </xsl:attribute>
  279.     <xsl:apply-templates/>
  280.   </a>
  281. </xsl:template>
  282.  
  283. <xsl:template match="qandaentry" mode="qandatoc.mode">
  284.   <xsl:apply-templates mode="qandatoc.mode"/>
  285. </xsl:template>
  286.  
  287. <xsl:template match="question" mode="qandatoc.mode">
  288.   <xsl:variable name="firstch" select="(*[name(.)!='label'])[1]"/>
  289.  
  290.   <dt>
  291.     <xsl:apply-templates select="." mode="label.markup"/>
  292.     <xsl:text> </xsl:text>
  293.     <a>
  294.       <xsl:attribute name="href">
  295.         <xsl:call-template name="href.target"/>
  296.       </xsl:attribute>
  297.       <xsl:value-of select="$firstch"/>
  298.     </a>
  299.   </dt>
  300. </xsl:template>
  301.  
  302. <xsl:template match="answer|revhistory" mode="qandatoc.mode">
  303.   <!-- nop -->
  304. </xsl:template>
  305.  
  306. <!-- ==================================================================== -->
  307.  
  308. <xsl:template match="*" mode="no.wrapper.mode">
  309.   <xsl:apply-templates/>
  310. </xsl:template>
  311.  
  312. <!-- ==================================================================== -->
  313.  
  314. </xsl:stylesheet>
  315. This resource fork intentionally left blank   ˇˇ